package chap4_5Properties类;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-17 15:41
 * @Description
 */
public class PropertiesDemo03 {
    public static void main(String[] args) throws IOException {
        //把集合中的数据保存到文件
        myStore();
        //把文件中的数据加载到集合
        myLoad();
    }

    private static void myLoad() throws IOException {
        Properties prop = new Properties();
        //void load(Reader reader)
        FileReader fr = new FileReader("chapter04-特殊操作流\\src\\chap4_5Properties类\\fw.txt");
        prop.load(fr);
        fr.close();
        System.out.println(prop);
    }

    private static void myStore() throws IOException {
        Properties prop = new Properties();
        prop.setProperty("id001", "刘一");
        prop.setProperty("id002", "陈二");
        prop.setProperty("id003", "张三");
        //void store(Writer writer, String comments)
        FileWriter fw = new FileWriter("chapter04-特殊操作流\\src\\chap4_5Properties类\\fw.txt");
        prop.store(fw, null);
        fw.close();
    }
}
